#ifndef __ZPP_VALUE_HPP__
#define __ZPP_VALUE_HPP__

#include <zephyr/drivers/sensor.h>
#include <zpp/assert.hpp>

namespace zpp {

class value : protected sensor_value {
public:
  constexpr value(int32_t v1, int32_t v2) : sensor_value(v1, v2) {}
  value(float v) { ZPP_ASSERT_EQ(sensor_value_from_float(this, v), 0); }
  value(double v) { ZPP_ASSERT_EQ(sensor_value_from_double(this, v), 0); }
  value(sensor_value &base) {
    this->val1 = base.val1;
    this->val2 = base.val2;
  }
  auto operator=(const value &other) -> value & {
    this->val1 = other.val1;
    this->val2 = other.val2;
    return *this;
  }
  auto operator-(const value &other) -> value & {
    this->val1 = this->val1 - other.val1;
    this->val2 = this->val2 - other.val2;
    return *this;
  }
  auto operator+(const value &other) -> value & {
    this->val1 = this->val1 + other.val1;
    this->val2 = this->val2 + other.val2;
    return *this;
  }
  auto operator*(const value &other) -> value & {
    this->val1 = this->val1 * other.val1;
    this->val2 = this->val2 * other.val2;
    return *this;
  }

  auto operator/(const value &other) -> value & {
    this->val1 = this->val1 / other.val1;
    this->val2 = this->val2 / other.val2;
    return *this;
  }
  auto to_float() const { return sensor_value_to_float(this); }
  auto to_double() const { return sensor_value_to_double(this); }
  auto to_milli() const { return sensor_value_to_milli(this); }
  auto to_micro() const { return sensor_value_to_micro(this); }
};

} // namespace zpp

#endif
